###############################################################################
# SuperLinks                                                                  #
# Written by Gregory Nolle (greg@nolle.co.uk)                                 #
# Copyright 2000-2003 by PlasmaPulse Solutions (http://www.plasmapulse.com)   #
###############################################################################
# Libraries/HTML/Dialog.pm -> Dialog html library                             #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package HTML::Dialog;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }

use HTML::Form;
use strict;

sub new {
  my $class = shift;
  my $self  = { };
  return bless($self, $class);
}

sub DESTROY { }

################################################################################
# Page subroutine
sub Page {
  my $self = shift;
  my %in = (
    "title"       => "SuperLinks Control Panel",
    "metas"       => [], # meta: { name => "", http_equiv => "", content => "" }
    "head_extra"  => "",
    "body_extra"  => "",
    "body"        => "",
    "no_style"    => 0,
    @_
  );

  push(@{$in{'metas'}}, { name => "GENERATOR", content => "SuperLinks $SL::VERSION, www.plasmapulse.com" });
  
  unless ($in{'no_style'}) {
    $in{'head_extra'} .= qq~<link type="text/css" href="$SYSTEM->{'PUBLIC_URL'}/cpstyles.css" rel="stylesheet">~;
    $in{'body_extra'} .= qq~ topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0"~;
  }

  my $Return = qq~<html>\n\n~;
  
  $Return .= qq~<head>\n~;
  $Return .= qq~<title>$in{'title'}</title>\n~;
  $Return .= $in{'head_extra'};
  
  foreach my $meta (@{ $in{'metas'} }) {
    $Return .= qq~<meta~;
    $Return .= qq~ name="$meta->{'name'}"~ if ($meta->{'name'});
    $Return .= qq~ http-equiv="$meta->{'http_equiv'}"~ if ($meta->{'http_equiv'});
    $Return .= qq~ content="$meta->{'content'}"~ if ($meta->{'content'});
    $Return .= qq~>\n~;
  }
  
  $Return .= qq~</head>\n\n~;
  
  $Return .= qq~<body~;
  $Return .= qq~ $in{'body_extra'}~ if ($in{'body_extra'});
  $Return .= qq~>\n\n~;
  
  $Return .= $in{'body'};
  
  $Return .= qq~</body>\n~;
  $Return .= qq~</html>\n~;
  
  return $Return;
}

################################################################################
# Form subroutine
sub Form {
  my $self = shift;
  
  my $Form = HTML::Form->new();
  
  return $Form->Form(@_);
}

################################################################################
# StandardPage subroutine
sub StandardPage {
  my $self = shift;
  my %in = (
    "header"      => "",
    "body"        => "",
    "form"        => 0,
    "multipart"   => 0,
    "hiddens"     => [],
    "toolbar"     => [],
    "metas"       => [],
    "form_extra"  => {},
    "head_extra"  => "",
    "body_extra"  => "",
    @_
  );
  
  my $Return  = $self->Header(title => $in{'header'});
     $Return .= $self->Toolbar(items => $in{'toolbar'}) if (scalar(@{ $in{'toolbar'} }) >= 1);
     $Return .= $self->Body(body => $in{'body'});
     $Return .= $self->BottomBar();
     
     $Return  = $self->Dialog(body => $Return);
     $Return  = $self->Main(body => $Return);
     $Return  = $self->Form(body => $Return, hiddens => $in{'hiddens'}, extra => $in{'form_extra'}, multipart => $in{'multipart'}) if ($in{'form'});
     $Return  = $self->Page(body => $Return, metas => $in{'metas'}, head_extra => $in{'head_extra'}, body_extra => $in{'body_extra'});

  return $Return;
}

################################################################################
# Menu subroutine
sub Menu {
  my $self = shift;
  my %in = ("icon" => "", "body" => "", @_);

  my $Return  = qq~      <table border="0" cellspacing="0" cellpadding="10" width="100%">\n~;
     $Return .= qq~        <tr>\n~;
  
  $Return .= qq~          <td align="center">$in{'icon'}</td>\n~;
  
  $Return .= qq~        </tr>\n~;
  $Return .= $in{'body'};
  $Return .= qq~      </table>\n~;

  return $Return;
}

################################################################################
# MenuBox subroutine
sub MenuBox {
  my $self = shift;
  my %in = ("body" => "", @_);

  return <<HTML;
        <tr>
          <td>
            <table border="0" cellspacing="0" width="100%" class="menu-box-border">
              <tr>
                <td>
                  <table border="0" cellpadding="1" cellspacing="4" width="100%" class="menu-box">
$in{'body'}
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
HTML

}

################################################################################
# MenuHeader subroutine
sub MenuHeader {
  my $self = shift;
  my %in = ("type" => "", "title" => "", "url" => "", "target" => "", @_); # type: active|inactive

  my $Return  = qq~                    <tr class="menu-header-$in{'type'}">\n~;
     $Return .= qq~                      <td>\n~;
     $Return .= qq~                        <table border="0" cellpadding="2" cellspacing="0" width="100%">\n~;
     $Return .= qq~                          <tr>\n~;
  
  if ($in{'url'}) {
    $Return .= qq~                            <td width="1" nowrap><a href="$in{'url'}"><img border="0" src="$SYSTEM->{'PUBLIC_URL'}/Images/menu_$in{'type'}.gif"></a></td>\n~;
    $Return .= qq~                            <td width="100%" align="center"><font class="menu-header-$in{'type'}"><a href="$in{'url'}" target="$in{'target'}">$in{'title'}</a></font></td>\n~;
  } else {
    $Return .= qq~                            <td width="1" nowrap><img border="0" src="$SYSTEM->{'PUBLIC_URL'}/Images/menu_$in{'type'}.gif"></td>\n~;
    $Return .= qq~                            <td width="100%" align="center"><font class="menu-header-$in{'type'}">$in{'title'}</font></td>\n~;
  }    

  $Return .= qq~                          </tr>\n~;
  $Return .= qq~                        </table>\n~;
  $Return .= qq~                      </td>\n~;
  $Return .= qq~                    </tr>\n~;
  
  return $Return;
}

################################################################################
# MenuBody subroutine
sub MenuBody {
  my $self = shift;
  my %in = ("body" => "", @_);

  return <<HTML;
                    <tr class="menu-body">
                      <td>$in{'body'}</td>
                    </tr>
HTML

}

################################################################################
# MenuIcons subroutine
sub MenuIcons {
  my $self = shift;
  my %in = ("icons" => [], @_); # icon: { icon => "", caption => "", url => "", target => "", extra => "" }
  
  my $Return = qq~                        <table border="0" cellpadding="1" cellspacing="1" width="100%">\n~;
  
  foreach my $icon (@{ $in{'icons'} }) {
    $Return .= qq~                          <tr>\n~;
    $Return .= qq~                            <td align="center"><font class="menu-body"><a href="$icon->{'url'}" class="menu-body" target="$icon->{'target'}"~;
    $Return .= qq~ $icon->{'extra'}~ if ($icon->{'extra'});
    $Return .= qq~><img border="0" src="$SYSTEM->{'PUBLIC_URL'}/Images/$icon->{'icon'}"><br>\n~;
    $Return .= qq~                              $icon->{'caption'}</a></font></td>\n~;
    $Return .= qq~                          </tr>\n~;
  }
  
  $Return .= qq~                        </table>\n~;
  
  return $Return;
}

################################################################################
# Main subroutine
sub Main {
  my $self = shift;
  my %in = ("body" => "", "nopowered" => 0, @_);

  my $Return  = qq~      <table border="0" cellspacing="0" cellpadding="10" width="100%" height="100%">\n~;
     $Return .= qq~        <tr height="1">\n~;
     $Return .= qq~          <td>\n~;
     $Return .= $in{'body'};
     $Return .= qq~          </td>\n~;
     $Return .= qq~        </tr>\n~;

  unless ($in{'nopowered'}) {
    $Return .= qq~        <tr height="100%">\n~;
    $Return .= qq~          <td align="right" valign="bottom"><font class="powered">Powered by <a href="http://www.plasmapulse.com/?sc=SuperLinks">SuperLinks</a> Standard Edition.<br>\n~;
    $Return .= qq~            Copyright 2000-2003 &copy; <a href="http://www.plasmapulse.com">PlasmaPulse Solutions</a>. All rights reserved.</font></td>\n~;
    $Return .= qq~        </tr>\n~;
  }
  
  $Return .= qq~      </table>\n~;
  
  return $Return;
}

################################################################################
# Dialog subroutine
sub Dialog {
  my $self = shift;
  my %in = ("body" => "", @_);

  return <<HTML;
            <table border="0" cellpadding="1" cellspacing="1" width="100%" class="main-border">
              <tr class="main-background">
                <td>
                  <table border="0" cellpadding="1" cellspacing="0" width="100%">
$in{'body'}
                  </table>
                </td>
              </tr>
            </table>
HTML

}

################################################################################
# Header subroutine
sub Header {
  my $self = shift;
  my %in = ("title" => "", "icons" => [], @_); # icon: { url => "", target => "", icon => "" }

  my $Return  = qq~                    <tr>\n~;
     $Return .= qq~                      <td>\n~;
     $Return .= qq~                        <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">\n~;
     $Return .= qq~                          <tr class="header">\n~;
     $Return .= qq~                            <td background="$SYSTEM->{'PUBLIC_URL'}/Images/headerbg.gif">\n~;
     $Return .= qq~                              <table border="0" cellspacing="0" cellpadding="1" width="100%">\n~;
     $Return .= qq~                                <tr>\n~;
     $Return .= qq~                                  <td width="2" nowrap></td>\n~;
     $Return .= qq~                                  <td width="100%"><font class="header">$in{'title'}</font></td>\n~;

  foreach my $icon (@{ $in{'icons'} }) {
    $Return .= qq~                                  <td width="1" nowrap><a href="$icon->{'url'}" target="$icon->{'target'}"><img border="0" src="$SYSTEM->{'PUBLIC_URL'}/Images/$icon->{'icon'}"></a></td>\n~;
  }

  $Return .= qq~                                </tr>\n~;
  $Return .= qq~                              </table>\n~;
  $Return .= qq~                            </td>\n~;
  $Return .= qq~                          </tr>\n~;
  $Return .= qq~                        </table>\n~;
  $Return .= qq~                      </td>\n~;
  $Return .= qq~                    </tr>\n~;

  return $Return;
}

################################################################################
# Toolbar subroutine
sub Toolbar {
  my $self = shift;
  my %in = ("items" => [], @_); # item: { type => "", url => "", target => "", icon => "", caption => "" } type: icon|divider

  my $Return  = qq~                    <tr>\n~;
     $Return .= qq~                      <td>\n~;
     $Return .= qq~                        <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">\n~;
     $Return .= qq~                          <tr class="toolbar">\n~;
     $Return .= qq~                            <td>\n~;
     $Return .= qq~                              <table border="0" cellspacing="0" cellpadding="0">\n~;
     $Return .= qq~                                <tr>\n~;
  
  foreach my $item (@{ $in{'items'} }) {
    if ($item->{'type'} eq "divider") {
      $Return .= qq~                                  <td rowspan="3" nowrap class="toolbar-divider"></td>\n~;
      $Return .= qq~                                  <td rowspan="3" nowrap width="5"></td>\n~;
    } else {
      $Return .= qq~                                  <td height="5"></td>\n~;
      $Return .= qq~                                  <td height="5"></td>\n~;
    }
  }  

  $Return .= qq~                                </tr>\n~;
  $Return .= qq~                                <tr>\n~;

  foreach my $item (@{ $in{'items'} }) {
    next if ($item->{'type'} eq "divider");

    $Return .= qq~                                  <td width="1" nowrap>\n~;
    $Return .= qq~                                    <table border="0" cellpadding="0" cellspacing="0" width="100%">\n~;
    $Return .= qq~                                      <tr>\n~;
    $Return .= qq~                                        <td align="center"><font class="toolbar"><a href="$item->{'url'}" target="$item->{'target'}" class="toolbar"><img border="0" src="$SYSTEM->{'PUBLIC_URL'}/Images/$item->{'icon'}"><br>\n~;
    $Return .= qq~                                          $item->{'caption'}</a></font></td>\n~;
    $Return .= qq~                                      </tr>\n~;
    $Return .= qq~                                    </table>\n~;
    $Return .= qq~                                  </td>\n~;
    $Return .= qq~                                  <td nowrap width="10"></td>\n~;
  }

  $Return .= qq~                                </tr>\n~;
  $Return .= qq~                                <tr>\n~;
  $Return .= qq~                                  <td height="5" colspan="~.((scalar(@{ $in{'items'} }) * 2) - 2).qq~"></td>\n~;
  $Return .= qq~                                </tr>\n~;
  $Return .= qq~                              </table>\n~;
  $Return .= qq~                            </td>\n~;
  $Return .= qq~                          </tr>\n~;
  $Return .= qq~                        </table>\n~;
  $Return .= qq~                      </td>\n~;
  $Return .= qq~                    </tr>\n~;

  return $Return;
}

################################################################################
# Body subroutine
sub Body {
  my $self = shift;
  my %in = ("body" => "", @_);
  
  return <<HTML;
                    <tr>
                      <td>
                        <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                          <tr class="body">
                            <td><font class="body">
$in{'body'}</font>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
HTML

}

################################################################################
# BottomBar subroutine
sub BottomBar {
  my $self = shift;
  my %in = ("body" => "", @_);
  
  return <<HTML;
                    <tr>
                      <td>
                        <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                          <tr class="bottombar">
                            <td><font class="bottombar">$in{'body'}</font></td>
                          </tr>
                        </table>
                      </td>
                    </tr>
HTML

}

################################################################################
# Table subroutine
sub Table {
  my $self = shift;
  my %in = ("body" => "", @_);
  
  return <<HTML;
                              <table border="0" cellspacing="1" cellpadding="0" width="100%" class="table-border">
                                <tr>
                                  <td>
                                    <table border="0" cellspacing="1" cellpadding="6" width="100%" class="table">
$in{'body'}
                                    </table>
                                  </td>
                                </tr>
                              </table>
HTML

}

################################################################################
# TableHeader subroutine
sub TableHeader {
  my $self = shift;
  my %in = ("titles" => [], @_); # title: { title => "", width => "", nowrap => "", colspan => "", align => "" }

  my $Return = qq~                                      <tr class="table-header">\n~;
  
  foreach my $title (@{ $in{'titles'} }) {
    $title->{'nowrap'}    = " nowrap" if ($title->{'nowrap'});
    $title->{'colspan'} ||= 1;
    $title->{'align'}   ||= "center";
    
    $Return .= qq~                                        <td align="$title->{'align'}" width="$title->{'width'}" colspan="$title->{'colspan'}"$title->{'nowrap'}><font class="table-header">$title->{'title'}</font></td>\n~;
  }

  $Return .= qq~                                      </tr>\n~;

  return $Return;
}

################################################################################
# TableSubHeader subroutine
sub TableSubHeader {
  my $self = shift;
  my %in = ("titles" => [], @_); # title: { title => "", width => "", nowrap => "", colspan => "", align => "" }

  my $Return = qq~                                      <tr class="table-sub-header">\n~;

  foreach my $title (@{ $in{'titles'} }) {
    $title->{'nowrap'}    = " nowrap" if ($title->{'nowrap'});
    $title->{'colspan'} ||= 1;
    $title->{'align'}   ||= "left";
    
    $Return .= qq~                                        <td align="$title->{'align'}" width="$title->{'width'}" colspan="$title->{'colspan'}"$title->{'nowrap'}><font class="table-sub-header">$title->{'title'}</font></td>\n~;
  }

  $Return .= qq~                                      </tr>\n~;

  return $Return;
}

################################################################################
# TableRow subroutine
sub TableRow {
  my $self = shift;
  my %in = ("items" => [], @_); # item: { body => "", width => "", nowrap => "", colspan => "", align => "" }

  my $Return = qq~                                      <tr class="table-row">\n~;

  foreach my $item (@{ $in{'items'} }) {
    $item->{'nowrap'}    = " nowrap" if ($item->{'nowrap'});
    $item->{'colspan'} ||= 1;
    $item->{'align'}   ||= "left";
    
    $Return .= qq~                                        <td align="$item->{'align'}" width="$item->{'width'}" colspan="$item->{'colspan'}"$item->{'nowrap'}><font class="table-row">$item->{'body'}</font></td>\n~;
  }

  $Return .= qq~                                      </tr>\n~;

  return $Return;
}

################################################################################
# TableDivider subroutine
sub TableDivider {
  my $self = shift;
  my %in = ("colspan" => 1, @_);

  return <<HTML;
                                      <tr class="table-row">
                                        <td colspan="$in{'colspan'}">
                                          <table border="0" cellspacing="0" cellpadding="0" width="100%">
                                            <tr>
                                              <td height="2" class="table-divider1"></td>
                                            </tr>
                                            <tr>
                                              <td height="1" class="table-divider2"></td>
                                            </tr>
                                          </table>
                                        </td>
                                      </tr>
HTML

}

################################################################################
# TableFooter subroutine
sub TableFooter {
  my $self = shift;
  my %in = ("items" => [], @_); # item: { body => "", width => "", nowrap => "", colspan => "", align => "" }

  my $Return = qq~                                      <tr class="table-footer">\n~;

  foreach my $item (@{ $in{'items'} }) {
    $item->{'nowrap'}    = " nowrap" if ($item->{'nowrap'});
    $item->{'colspan'} ||= 1;
    $item->{'align'}   ||= "left";
    
    $Return .= qq~                                        <td align="$item->{'align'}" width="$item->{'width'}" colspan="$item->{'colspan'}"$item->{'nowrap'}><font class="table-footer">$item->{'body'}</font></td>\n~;
  }

  $Return .= qq~                                      </tr>\n~;

  return $Return;
}

################################################################################
# TableToolbar subroutine
sub TableToolbar {
  my $self = shift;
  my %in = ("items" => [], @_); # item: { type => "", url => "", target => "", icon => "", caption => "" } type: icon|divider

  my $Return  = qq~                                          <table border="0" cellspacing="0" cellpadding="0" width="100%">\n~;
     $Return .= qq~                                            <tr class="toolbar">\n~;
     $Return .= qq~                                              <td>\n~;
     $Return .= qq~                                                <table border="0" cellspacing="0" cellpadding="0">\n~;
     $Return .= qq~                                                  <tr>\n~;

  foreach my $item (@{ $in{'items'} }) {
    if ($item->{'type'} eq "divider") {
      $Return .= qq~                                                    <td rowspan="3" nowrap class="toolbar-divider"></td>\n~;
      $Return .= qq~                                                    <td rowspan="3" nowrap width="5"></td>\n~;
    } else {
      $Return .= qq~                                                    <td height="5"></td>\n~;
      $Return .= qq~                                                    <td height="5"></td>\n~;
    }
  }  

  $Return .= qq~                                                  </tr>\n~;
  $Return .= qq~                                                  <tr>\n~;

  foreach my $item (@{ $in{'items'} }) {
    next if ($item->{'type'} eq "divider");

    $Return .= qq~                                                    <td width="1" nowrap>\n~;
    $Return .= qq~                                                      <table border="0" cellpadding="0" cellspacing="0" width="100%">\n~;
    $Return .= qq~                                                        <tr>\n~;
    $Return .= qq~                                                          <td align="center"><font class="toolbar"><a href="$item->{'url'}" target="$item->{'target'}" class="toolbar"><img border="0" src="$SYSTEM->{'PUBLIC_URL'}/Images/$item->{'icon'}"><br>\n~;
    $Return .= qq~                                                            $item->{'caption'}</a></font></td>\n~;
    $Return .= qq~                                                        </tr>\n~;
    $Return .= qq~                                                      </table>\n~;
    $Return .= qq~                                                    </td>\n~;
    $Return .= qq~                                                    <td nowrap width="10"></td>\n~;
  }

  $Return .= qq~                                                  </tr>\n~;
  $Return .= qq~                                                  <tr>\n~;
  $Return .= qq~                                                    <td height="5" colspan="~.((scalar(@{ $in{'items'} }) * 2) - 2).qq~"></td>\n~;
  $Return .= qq~                                                  </tr>\n~;
  $Return .= qq~                                                </table>\n~;
  $Return .= qq~                                              </td>\n~;
  $Return .= qq~                                            </tr>\n~;
  $Return .= qq~                                          </table>\n~;

  return $Return;
}

################################################################################
# FormTextBox subroutine
sub FormTextBox {
  my $self = shift;
  my %in = (
    "name"        => "",
    "value"       => "",
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    "password"    => 0,
    "empty"       => 0,
    @_
  );
  
  my $Form = HTML::Form->new();

  my $Field;
  if ($in{'name'}) {
    $Field = $Form->TextBox(name => $in{'name'}, value => $in{'value'}, password => $in{'password'}, empty => $in{'empty'});
  } else {
    $Field = qq~<font class="form-field">$in{'value'}</font>~;
  }

  return $self->myFormField(%in, field => $Field);
}

################################################################################
# FormFileBox subroutine
sub FormFileBox {
  my $self = shift;
  my %in = (
    "name"        => "",
    "value"       => "",
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    "password"    => 0,
    "empty"       => 0,
    @_
  );
  
  my $Form = HTML::Form->new();

  my $Field;
  if ($in{'name'}) {
    $Field = $Form->FileBox(name => $in{'name'}, value => $in{'value'}, password => $in{'password'}, empty => $in{'empty'});
  } else {
    $Field = qq~<font class="form-field">$in{'value'}</font>~;
  }

  return $self->myFormField(%in, field => $Field);
}

################################################################################
# FormTextArea subroutine
sub FormTextArea {
  my $self = shift;
  my %in = (
    "name"        => "",
    "value"       => "",
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    "empty"       => 0,
    "rows"        => 1,
    @_
  );
  
  my $Form = HTML::Form->new();

  my $Field;
  if ($in{'name'}) {
    $Field = $Form->TextArea(name => $in{'name'}, value => $in{'value'}, empty => $in{'empty'}, rows => $in{'rows'});
  } else {
    $Field = qq~<font class="form-field">$in{'value'}</font>~;
  }
  
  return $self->myFormField(%in, field => $Field);
}

################################################################################
# FormRadio subroutine
sub FormRadio {
  my $self = shift;
  my %in = (
    "name"        => "",
    "value"       => "",
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    "empty"       => 0,
    "items"       => [], # item: { value => "", label => "" }
    "join"        => "",
    @_
  );
  
  my $Form = HTML::Form->new();

  my $Field;
  if ($in{'name'}) {
    $Field = $Form->Radio(name => $in{'name'}, value => $in{'value'}, empty => $in{'empty'}, items => $in{'items'}, join => $in{'join'});
  } else {
    my $label;
    foreach my $item (@{ $in{'items'} }) {
      $label = $item->{'label'} if ($item->{'value'} eq $in{'value'});
    }
    $Field = qq~<font class="form-field">$label</font>~;
  }
  
  return $self->myFormField(%in, field => $Field);
}

################################################################################
# FormCheckBox subroutine
sub FormCheckBox {
  my $self = shift;
  my %in = (
    "name"        => "",
    "value"       => undef,
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    "empty"       => 0,
    "items"       => [], # item: { value => "", label => "" }
    "join"        => "",
    @_
  );
  
  my $Form = HTML::Form->new();

  my $Field;
  if ($in{'name'}) {
    $Field = $Form->CheckBox(name => $in{'name'}, value => $in{'value'}, empty => $in{'empty'}, items => $in{'items'}, join => $in{'join'});
  } else {
    my %values;
    if (ref($in{'value'}) eq "ARRAY") {
      foreach my $value (@{ $in{'value'} }) {
        $values{ $value } = 1;
      }
    } elsif (ref($in{'value'}) eq "HASH") {
      %values = %{ $in{'value'} };
    } else {
      $values{ $in{'value'} } = 1;
    }
    
    my @label;
    foreach my $item (@{ $in{'items'} }) {
      push(@label, $item->{'label'}) if ($values{ $item->{'value'} });
    }
    $Field = qq~<font class="form-field">~.join($in{'join'}, @label).qq~</font>~;
  }
  
  return $self->myFormField(%in, field => $Field);
}

################################################################################
# FormSelectBox subroutine
sub FormSelectBox {
  my $self = shift;
  my %in = (
    "name"        => "",
    "value"       => undef,
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    "empty"       => 0,
    "items"       => [], # item: { value => "", label => "" }
    "join"        => "",
    "rows"        => 1,
    "multiple"    => 0,
    "extra"       => {},
    @_
  );
  
  my $Form = HTML::Form->new();

  my $Field;
  if ($in{'name'}) {
    $Field = $Form->SelectBox(name => $in{'name'}, value => $in{'value'}, empty => $in{'empty'}, items => $in{'items'}, rows => $in{'rows'}, multiple => $in{'multiple'}, extra => $in{'extra'});
  } else {
    my %values;
    if (ref($in{'value'}) eq "ARRAY") {
      foreach my $value (@{ $in{'value'} }) {
        $values{ $value } = 1;
      }
    } elsif (ref($in{'value'}) eq "HASH") {
      %values = %{ $in{'value'} };
    } else {
      $values{ $in{'value'} } = 1;
    }
    
    my @label;
    foreach my $item (@{ $in{'items'} }) {
      push(@label, $item->{'label'}) if ($values{ $item->{'value'} });
    }
    $Field = qq~<font class="form-field">~.join($in{'join'}, @label).qq~</font>~;
  }
  
  return $self->myFormField(%in, field => $Field);
}

################################################################################
# FormButton subroutine
sub FormButton {
  my $self = shift;
  my %in = (
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    "items"       => [], # item: { type => "", value => "", label => "", src => "" }
    "join"        => "",
    @_
  );
  
  my $Form = HTML::Form->new();

  my $Field = $Form->Button(items => $in{'items'}, join => $in{'join'});
  
  return $self->myFormField(%in, field => $Field);
}

################################################################################
# myFormField subroutine
sub myFormField {
  my $self = shift;
  my %in = (
    "field"       => "",
    "subject"     => "",
    "sub_subject" => "",
    "sub_field"   => "",
    "help"        => "",
    "iconhelp"    => "",
    "required"    => 0,
    @_
  );

  my $Return  = qq~                                      <tr class="table-row">\n~;
     $Return .= qq~                                        <td width="200" valign="top" nowrap><font class="form-subject">$in{'subject'}~;
     $Return .= qq~ <font class="form-required">*</font>~ if ($in{'required'});
     $Return .= qq~</font>\n~;
     $Return .= qq~                                          <br><font class="form-sub-subject">$in{'sub_subject'}</font></td>~ if ($in{'sub_subject'});

  if ($in{'help'} || $in{'iconhelp'}) {
    $Return .= qq~                                        <td width="100%">\n~;
    $Return .= qq~                                          <table border="0" cellspacing="0" cellpadding="0" width="100%">\n~;
    $Return .= qq~                                            <tr>\n~;
    $Return .= qq~                                              <td width="100%">$in{'field'}~;
    $Return .= qq~\n                                                <font class="form-sub-field">$in{'sub_field'}</font>~ if ($in{'sub_field'});
    $Return .= qq~</td>\n~;
    
    if ($in{'help'}) {
      $Return .= qq~                                              <td width="5" nowrap></td>\n~;
      $Return .= qq~                                              <td width="200" nowrap><font class="form-help">$in{'help'}</font></td>\n~;
    }
    
    if ($in{'iconhelp'}) {
      my $subject = $in{'subject'};
         $subject =~ s/\'/\\\'/g;
      my $help    = $in{'iconhelp'};
         $help    =~ s/\'/\\\'/g;
      $Return .= qq~                                              <td width="5" nowrap></td>\n~;
      $Return .= qq~                                              <td width="1" nowrap><a href="javascript:Tooltip('$subject', '$help', '$SYSTEM->{'PUBLIC_URL'}');"><img border="0" src="$SYSTEM->{'PUBLIC_URL'}/Images/iconhelp.gif" alt="$in{'iconhelp'}"></a></td>\n~;
    }
    
    $Return .= qq~                                            </tr>\n~;
    $Return .= qq~                                          </table>\n~;
  } else {
    $Return .= qq~                                        <td width="100%">$in{'field'}~;
    $Return .= qq~\n                                          <br><font class="form-sub-field">$in{'sub_field'}</font>~ if ($in{'sub_field'});
    $Return .= qq~</td>\n~;
  }
  
  $Return .= qq~                                      </tr>\n~;
  
  return $Return;
}

1;